package com.seata.demo.order.feign;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.math.BigDecimal;

@FeignClient(name = "account-service")
//@LocalTCC
public interface TccAccountFeignClient {

    @TwoPhaseBusinessAction(name = "accountTccAction", commitMethod = "commit", rollbackMethod = "rollback")
    @PostMapping("/account/tcc/tryDebit")
    boolean tryDebit(
            @BusinessActionContextParameter(paramName = "userId") @RequestParam("userId") String userId,
            @BusinessActionContextParameter(paramName = "money") @RequestParam("money") BigDecimal money);

    @PostMapping("/account/tcc/commit")
    boolean commit(BusinessActionContext context);

    @PostMapping("/account/tcc/rollback")
    boolean rollback(BusinessActionContext context);
}
